package com.example.socket;

import java.io.*;
import java.net.Socket;

/**
 * @author hej
 * @date 2024/9/11 13:22
 */
public class SimpleClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 8888);

        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        InputStream iStream = socket.getInputStream();         //输入流
        BufferedReader in = new BufferedReader(new InputStreamReader(iStream));

        out.println("Hello, Server!");
        System.out.println("Server said: " + in.readLine());


        BufferedReader bReader = new BufferedReader(new InputStreamReader(iStream)) ;
        String msg = bReader.readLine();

        System.out.println("客户端读取到服务端返回的消息：" + msg);

        out.close();
        in.close();
        socket.close();
    }
}
